<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<meta name="format-detection" content="telephone=no, address=no, email=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="misapplication-tap-highlight" content="no" />
		<meta name="HandheldFriendly" content="true" />
		<title>添加渠道</title>
		<link rel="stylesheet" href="../../css/mui.min.css" type="text/css" charset="utf-8" />
		<link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />

	</head>

	<body>
		<header class="mui-bar mui-bar-nav mui-header">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">添加渠道</h1>
		</header>
		<div class="mui-content">
			<form class="mui-input-group group-form ease transition" id="group-form" style="margin-left:0px;margin-right:0px;">
				<div class="mui-input-row">
					<label>姓名</label>
					<input type="text" class="mui-input-clear" id="ename" placeholder="请填写姓名">
				</div>
				<div class="mui-input-row">
					<label>手机号</label>
					<input type="text" class="mui-input-clear" id="mobile" placeholder="请填写手机号">
				</div>

				<div style="text-align: right;color:#f00;font-size:12px;">
					登录信息将发送至本手机号
				</div>
				<div id="message" style="color:#f00" class="none transition">
					<label>用户名或者密码错误</label>
				</div>

				<div class="mui-button-row" style="margin-top:0.5rem">
					<button type="button" class="mui-btn mui-btn-primary mui-btn-full" id="nextStep" style="height:44px;background:#f1c40f;color:#fff;border-color:#f1c40f">下一步</button>
				</div>

			</form>
		</div>

	</body>
	<script src="../../js/resize.js"></script>
	<script src="../../js/mui.min.js"></script>
	<script src="../../js/app.js"></script>
	<script src="../../js/ajaxFun.js"></script>
 
	<script>
	var currentView,flag,productNo;
		(function($, doc) {
			$.plusReady(function() {
				plus.nativeUI.closeWaiting();
				currentView=plus.webview.currentWebview();
				flag=currentView.flag;
				productNo=currentView.productNo;
				var users = JSON.parse(localStorage.getItem('$users') || '[]');
				/*下一步*/
				var jxsInfoRegisterAbleButton = document.getElementById("nextStep");
				jxsInfoRegisterAbleButton.addEventListener('tap', function() {
					/*判断手机号是否存在，如果在ID就是jxsInfoRegisterEnable ,否则id就是jxsInfoRegisterAble*/
					var mobile = document.getElementById("mobile").value;
					var ename = document.getElementById("ename").value;
					if(!ename) {
						plus.nativeUI.alert('请填写姓名');
						return false;
					}else if(ename.length > 10) {
						plus.nativeUI.alert('姓名不得超过10个字');
						return false;
					}else if(testStr(ename)){
						plus.nativeUI.alert('姓名不能包含非法字符！'); 
						return false;
					}
					if(!mobile) {
						plus.nativeUI.alert('请填写手机号');
						return false;
					} else {
						if(!app.checkTel(mobile)) {
							plus.nativeUI.alert('手机号码格式不正确');
							return false;
						}
						ajaxFun.postFun(baseUrl + 'dealersController/getJudgePhone.do', {
							mobile: mobile,
							name:ename
						}, '', function(d) {
							if(d.msg == '手机号不存在') {
								openWindow('jxsInfoRegisterAble.html','jxsInfoRegisterAble',{"name":ename,"mobile":mobile});
							} else if(d.msg == '手机号已存在') {
								//判断用户添加的对象是否是当前登录的对象
								var users = JSON.parse(localStorage.getItem('$users') || '[]');
								if(users.loginID!=d.data.traderInfoDto.id){
									openWindow('jxsInfoRegisterEnable.html','jxsInfoRegisterEnable',{"data":d.data.traderInfoDto});
								}else{
									plus.nativeUI.alert('对不起，您不能添加自己为下级经销商');	
								}
							}else{
								plus.nativeUI.alert(d.msg);
							}
						})

					}
				})
			})
		}(mui, document))

		mui.back=function(){
			currentView.hide();
			var detailPage = plus.webview.getWebviewById('jxsChild');
			 //触发重新加载子webview事件
			mui.fire(detailPage,'reloadChild',{
			    flag:flag,
				productNo:productNo,
				name:''
			});
		}
		
		function toPage(pageId,params) {
			var array = plus.webview.all();
			var mainPage = plus.webview.getWebviewById(pageId);
			//使用定时器的原因：
			//可能执行太快，main页面loaded事件尚未触发就执行自定义事件，此时必然会失败
			var id = setInterval(function() {
				clearInterval(id);
				mui.fire(mainPage, 'show', params); 
				mainPage.show("pop-in");
			}, 20);
		};
	</script>

</html>